package com.test.socket.demo1;

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.net.Socket;
/**
 * 
 * @author Administrator
 * @explain 如果没有服务器端那么一启动就会报错
 */
public class Client {

	public static void main(String[] args)  {
		int i = 0;
			Socket socket = null;
			InputStream is = null;
			try {
				socket = new Socket("127.0.0.1", 33333);
				PrintWriter pw = new PrintWriter(socket.getOutputStream());
				i++;
				pw.print("测试测试" + i);
				pw.flush();
				socket.shutdownOutput();
				is = socket.getInputStream();
				byte[] b = new byte[8096];
				int count = is.read(b);
				String response = new String(b, 0, count);
				System.out.println(response);
			} catch (IOException e) {
				e.printStackTrace();
			} finally {
				try {
					is.close();
					socket.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
	}
}
